//Helper function templates for working with game objects stored in std::list
#ifndef _GAMEOBJLIST_H_
#define _GAMEOBJLIST_H_


#include <list>
#include <cassert>


//Generic objects update function
template <typename tc_ObjectClass> void GameObjectsList_Update(std::list<tc_ObjectClass*>& List, float dt)
{

	std::list<tc_ObjectClass*>::iterator Iter = List.begin();

	tc_ObjectClass* pObj;

	while (Iter != List.end())
	{
		pObj = *Iter;

		pObj->Update(dt);

		if(pObj->IsDead() == true)
		{
			UTIL_SAFE_DELETE(pObj);
			Iter = List.erase(Iter);
		}
		else
		{
			Iter++;
		}
	}
}//template <typename tc_ObjectClass> void GameObjectsList_Update(std::list<tc_ObjectClass*>& List, float dt)



//Generic objects update function without killing objects
template <typename tc_ObjectClass> void GameObjectsList_UpdateNoKills(std::list<tc_ObjectClass*>& List, float dt)
{
	std::list<tc_ObjectClass*>::iterator Iter;

	for (Iter = List.begin(); Iter != List.end(); Iter++)
		(*Iter)->Update(dt);

}//template <typename tc_ObjectClass> void GameObjectsList_UpdateNoKills(std::list<tc_ObjectClass*>& List, float dt)



//Generic objects render function
template <typename tc_ObjectClass> void GameObjectsList_Render(std::list<tc_ObjectClass*>& List)
{
	std::list<tc_ObjectClass*>::iterator Iter;

	for (Iter = List.begin(); Iter != List.end(); Iter++)
		(*Iter)->Render();

}//template <typename tc_ObjectClass> void GameObjectsList_Render(std::list<tc_ObjectClass*>& List)



//Generic objects render function (layered)
template <typename tc_ObjectClass> void GameObjectsList_RenderLayer(std::list<tc_ObjectClass*>& List, int Layer)
{

	std::list<tc_ObjectClass*>::iterator Iter;

	for (Iter = List.begin(); Iter != List.end(); Iter++)
		(*Iter)->Render(Layer);

}//template <typename tc_ObjectClass> void GameObjectsList_RenderLayer(std::list<tc_ObjectClass*>& List, int Layer)



//Generic objects list clearing function
template <typename tc_ObjectClass> void GameObjectsList_Clear(std::list<tc_ObjectClass*>& List)
{

	std::list<tc_ObjectClass*>::iterator Iter;
	
	for (Iter = List.begin(); Iter != List.end(); Iter++)
		UTIL_SAFE_DELETE(*Iter);

	List.clear();

}//template <typename tc_ObjectClass> void GameObjectsList_Clear(std::list<tc_ObjectClass*>& List)



//Generic objects list adding new object function
template <typename tc_ObjectClass> void GameObjectsList_AddObject(std::list<tc_ObjectClass*>& List, tc_ObjectClass* pNewObject)
{
	assert(pNewObject != NULL);
	List.push_back(pNewObject);

}//template <typename tc_ObjectClass> void GameObjectsList_AddObject(std::list<tc_ObjectClass*>& List, tc_ObjectClass* pNewObject)


//Generic objects list sending an event to all objects
template <typename tc_ObjectClass> void GameObjectsList_SendEvent(std::list<tc_ObjectClass*>& List, const std::string& EventID)
{

	std::list<tc_ObjectClass*>::iterator Iter;

	for (Iter = List.begin(); Iter != List.end(); Iter++)
		(*Iter)->ReceiveEvent(EventID);

}//template <typename tc_ObjectClass> void GameObjectsList_SendEvent(std::list<tc_ObjectClass*>& List, const std::string& EventID)









#endif